﻿package cn.poco.pepsi.util.xmlparse;

import java.io.InputStream;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;
import cn.poco.pepsi.bean.Dish;


public class DishXmlparse {
	//private final static String TAG = "CityXmlparse";
	private static ArrayList<Dish> dishs = null;
	private static  Dish dishBean = null;
	
	public static ArrayList<Dish> getXml(InputStream inSteam,String citycode) throws Exception{
		XmlPullParser xmpparse = Xml.newPullParser();   //得到解释器
		xmpparse.setInput(inSteam, "UTF-8");           //设置解释流
		int code = xmpparse.getEventType();            //得到节点信息
		String id  = null;
		while(code!=XmlPullParser.END_DOCUMENT){
			switch (code) {
			case XmlPullParser.START_DOCUMENT:
				dishs = new ArrayList<Dish>();
				break;
			case XmlPullParser.START_TAG:
				if("dish".equals(xmpparse.getName())){
					dishBean = new Dish();
				}
				if(dishBean!=null){
					if("id".equals(xmpparse.getName())){
						id = xmpparse.nextText();
						if(id!=null && !id.equals("")){
							dishBean.setId(Long.parseLong(id));
							dishBean.setCitycode(citycode);
						}
						
					}
					if("name".equals(xmpparse.getName())){
						String name = xmpparse.nextText();
						dishBean.setCitycode(citycode);
						dishBean.setName(name);
					}
				}
				break;
			case XmlPullParser.END_TAG:
				if("dish".equals(xmpparse.getName())){
					//if(id!=null && !id.equals("")){
						dishs.add(dishBean);
					//}
					dishBean = null;
				}
				break;
			}	
			code = xmpparse.next();
		}
		inSteam.close();
		return dishs;
	}
}
